<?php


Zend_Loader::loadClass("BaseDBRows");
Zend_Loader::loadClass("SupplierPerformance");
class SupplierPerformances extends BaseDBRows
{
	protected function setUp()
	{
		$this->_tableName = SupplierPerformance::_tablename;
	}	
	
	
	public function getSupplierPerformance($org_id,$param=array()){
		
		Zend_Loader::loadClass("QueryCreator");
		Zend_Loader::loadClass("Receipt");
		Zend_Loader::loadClass("purchaseOrder");
		Zend_Loader::loadClass("Organization");
		
		$query = new QueryCreator();
		
		$query->addSelect(" po.po_no,org.name,a.date_evaluated,a.comments,a.ssp_id,po.po_id,rcpt.receipt_id ");
		$query->addFrom($this->_tableName . " a ");
		$query->addJoin(" LEFT JOIN ". Receipt::_tablename . " rcpt on a.reference_receipt_id = rcpt.receipt_id" );
		$query->addJoin(" LEFT JOIN ". purchaseOrder::_tablename . " po on po.po_id = rcpt.reference_id ");
		$query->addJoin(" LEFT JOIN ". Organization::_tablename . " org on org.org_id = a.supplier_org_id ");
		$query->addWhere(" evaluator_org_id = ". $org_id );
		
		if($param['supplier']) 
			$query->addWhere(" a.supplier_org_id = ". $param['supplier']);
			
		if($param['datefrom'] && $param['dateto']) {
			$query->addWhere(" a.date_evaluated between '". $param['datefrom'] ."' and '". $param['dateto'] ."'" );
		}
		
		//if($param['datefrom'] && strlen($param['dateto']) ) {
		
		$db = DBCon::instance();
		//echo $query->createSQL();
		$result = $db->executeQuery($query->createSQL());
		
		return $result;
		
		
	}
}
?>